<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var isAnagram = function (s, t) {
        if (s.length != t.length) {
          return false;
        }
        let sMap = new Map();
        for (let i = 0; i < s.length; i++) {
          if (sMap.has(s[i])) {
            let cur = sMap.get(s[i]);
            sMap.set(s[i], ++cur);
          } else {
            sMap.set(s[i], 1);
          }
        }
        let tMap = new Map();
        for (let i = 0; i < t.length; i++) {
          if (tMap.has(t[i])) {
            let cur = tMap.get(t[i]);
            tMap.set(t[i], ++cur);
          } else {
            tMap.set(t[i], 1);
          }
        }
        console.log(sMap,tMap);
        for (let [key, value] in sMap) {
          if (tMap.get(key) != value) return false;
        }
        return true;
      };

        isAnagram("rat", "car");
    </script>
  </body>
</html>
